package io.sdl.common.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.sdl.common.constant.UrlConstants;
import io.sdl.common.service.impl.CrudServiceImpl;
import io.sdl.common.sys.dao.SdlInstitutionPicDao;
import io.sdl.common.sys.dto.SdlInstitutionPicDTO;
import io.sdl.common.sys.entity.SdlInstitutionPicEntity;
import io.sdl.common.sys.service.SdlInstitutionPicService;
import io.sdl.common.utils.ConvertUtils;
import io.sdl.common.utils.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


@Service
public class SdlInstitutionPicServiceImpl extends CrudServiceImpl<SdlInstitutionPicDao, SdlInstitutionPicEntity, SdlInstitutionPicDTO> implements SdlInstitutionPicService {



    @Override
    public Integer getNum(Query query) {
        return baseDao.getNum(query);
    }

    @Override
    public List<SdlInstitutionPicDTO> getInstitutionPicById(Query query) {
        List<SdlInstitutionPicEntity> institutionPicById = baseDao.getInstitutionPicById(query);
        List<SdlInstitutionPicDTO> sdlInstitutionPicDTOS = ConvertUtils.sourceToTarget(institutionPicById, SdlInstitutionPicDTO.class);
        sdlInstitutionPicDTOS.forEach(p->{
            p.setPicList(Arrays.stream(p.getPic().split(",")).toList());
        });
        return sdlInstitutionPicDTOS;
    }

    //获取机构相关介绍
    @Override
    public List<SdlInstitutionPicDTO> getPicList(Long institutionId) {
        List<SdlInstitutionPicEntity> picList = baseDao.getPicList(institutionId);
        List<SdlInstitutionPicDTO> sdlInstitutionPicDTOS = ConvertUtils.sourceToTarget(picList, SdlInstitutionPicDTO.class);
        sdlInstitutionPicDTOS.forEach(p->{

            ArrayList<String> url = new ArrayList<>();
            Arrays.stream(p.getPic().split(",")).toList().forEach(pic->{
                url.add(UrlConstants.getProductionUrl() + pic);
                });
            p.setPicList(url);
            });
        return sdlInstitutionPicDTOS;
    }

    @Override
    public QueryWrapper<SdlInstitutionPicEntity> getWrapper(Map<String, Object> params) {
        return null;
    }
}
